package com.wl.network.demo05;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class UDPSender {
    public static void main(String[] args) {
        try {
            DatagramSocket datagramSocket = new DatagramSocket();
            //控制台读取需要发送消息
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            while (true){
                String data = reader.readLine();
                byte[] datas = data.getBytes();
                DatagramPacket datagramPacket = new DatagramPacket(datas,0,datas.length,new InetSocketAddress("localhost",9090));
                datagramSocket.send(datagramPacket);
                if (data.equals("0")){
                    break;
                }
            }
            datagramSocket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
